package com.start.avue.calculate;

import java.math.BigDecimal;
import java.util.Collection;

/**
 * 平均值
 */
public class StartAvgCalculate implements StartCalculate {
    public static String CALCULATE_TYPE_AVG = "avg";


    public StartAvgCalculate() {

    }

    @Override
    public String calculateType() {
        return CALCULATE_TYPE_AVG;
    }

    @Override
    public BigDecimal calculate(BigDecimal pre, BigDecimal cur, int index, Collection<?> collection) {
        BigDecimal decimal = pre.add(cur);
        if (index == collection.size() - 1) {
            BigDecimal count = new BigDecimal(collection.size());
            return decimal.divide(count);
        }
        return decimal;
    }
}
